<!-- 
      WarCache Google Gadget
      
      Created by NerfedWar <nerfed.war@gmail.com> on 2010-11-17.
      Copyright 2010 NerfedWar. All rights reserved.
 -->

<!-- ========= -->
<!-- = Style = -->
<!-- ========= -->
<link rel="stylesheet" href="http://warcache.googlecode.com/hg/jquery-ui.css" type="text/css" media="all" />

<style>

body {  
	margin:0; padding: 0; border: none; 
	background: black;
	font-family:Arial;
	font-size:11px;
	font-weight:bold;
	text-decoration:none;
	width: 100%;
	height: 600px;
	overflow: none;
	text-align: center;
	color: white;
}

.panel {
	position: relative;
	display: none;
  margin-left: auto;
  margin-right: auto;
}

.menuItem {  
	padding: 0 8px 0 8px;
	cursor: pointer; text-decoration: none; color: yellow
}

</style>

<!-- ========== -->
<!-- = Script = -->
<!-- ========== -->
<script type="text/javascript" src="https://www.google.com/jsapi?key=ABQIAAAARChIkzotDS7mBVsWYbS07xSIfeHlvFYvOEZAYiIJwAzWpNDGIhT9VcgTBKDlb6IW-Z0595N2H-7TVg"></script> 

<script type="text/javascript">
  
// load libraries and set onload function
google.load("jquery", "1.4.3");
google.load("jqueryui", "1.8.6");
google.load('visualization', '1', {'packages' : ['table']});
google.setOnLoadCallback(init);

// trap back button
window.history.forward(1);

// global variables
var dataSourceUrl = "http://spreadsheets.google.com/tq?key=0AhqHFpvBhkNTdGF5MnNDU09iVjF5eFh3emlJSVZfVXc&pub=1&sheet=AbilityData";

var dataTable = null;

/*
	performs global initialisation of the WarCache gadget
*/
var panelPrefixes = new Array('search', 'detail', 'listing', 'builder', 'about');
function init() {
	
	// initialise panels
	for (panelPrefix in panelPrefixes) {
		window[panelPrefixes[panelPrefix]+'Init']();
	}
	
	// if we are passed an ability Id then we need to switch to the detail panel
	// otherwise default to the search panel
	if(getAbilityId()) {
		switchPanel('detail');
		detailUpdate(getAbilityId());
	} else {
		switchPanel('search');
	}
}

/*
	switches to a panel by hiding the rest and calls the panelSwitch function of the panel.
*/
function switchPanel(panel) {
	$('.panel').hide();
	$('#'+panel+"Panel").show();
	window[panel+'Switch']();
}

/*
	extracts the abilityId from http get params
*/
function getAbilityId() {
    var vars = [],
    parentVars = [],
    hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
		// if we're embedded as a gadget we need to go to the parent
		if(vars['parent']) {
	    var parentURL = unescape(vars['parent']);
	    var hashes = parentURL.slice(parentURL.indexOf('?') + 1).split('&');
	    for (var i = 0; i < hashes.length; i++) {
	        hash = hashes[i].split('=');
	        parentVars.push(hash[0]);
	        parentVars[hash[0]] = hash[1];
	    }
	    return parentVars['id'];
		}
		
		// return id
		return vars['id'];
}

</script>

<!-- ======== -->
<!-- = HTML = -->
<!-- ======== -->
